<?php
$id_category = (isset($this->pageValues['id_category'])) ? $this->pageValues['id_category'] : '';
echo $this->menuBuilder($this->menus, $id_category);
?>
<div class="orange_line" >&nbsp;</div>
<?php echo $this->form_search;?>
<div class="left_col">
    <?php echo $this->partial("index/_orderControl.phtml");?>

    <?php if (!empty($this->msg_shopping_cart)):?>
        <div class="msg_successful">
            <p><?php echo $this->translate($this->msg_shopping_cart)?></p>
        </div>
    <?php endif;?>  

    <table class="tbl_cart_products" id="tbl_cart_products">
    <thead>
        <tr>
            <th>
                <span class="tbl_item_name">
                    <?php echo $this->translate('CART_ITEM_NAME') ?>
                </span>
            </th>
            <th>
                <span class="tbl_quantity">
                    <?php echo $this->translate('CART_ITEM_QUANTITY') ?>
                </span>
            </th>
            <th>
                <span class="tbl_payment">
                    <?php echo $this->translate('CART_ITEM_SUB_TOTAL') ?>
                </span>
            </th>
        </tr>
    </thead>
    <tbody>
        <?php
            if(count($this->list_products)):
                foreach ($this->list_products as $key => $product):		
        ?>
        <tr class="cart_product_row">
            <td>
                <div class="product_cover">
                    <a  href="<?php echo $this->pageUrl(array('target' => 'detail','id' => $product['id_store'], 'id_product' => $product['id'])); ?>">
                        <img alt="thumbnail" src="<?php echo $product['thumbnail'];?>">
                    </a>
                </div>
                <div class="product_info">
                    <p class="product_name">
                        <a  href="<?php echo $this->pageUrl(array('target' => 'detail','id' => $product['id_store'], 'id_product' => $product['id'])); ?>">
                            <?php echo $this->escape($product['name']) ?>
                        </a>
                    </p>
                    <?php if(!empty($product['sku'])):?>
                    <p class="product_SKU">
                        <label><?php echo $this->translate('SKU'); ?>:</label>
                        <span><?php echo $this->escape($product['sku']);?></span>
                    </p>
                    <?php endif;?>
                    <p class="price_info">
                        <span value="<?php echo isset($product['price'])?$product['price']:'N/A';?>" class="price">
                            <?php echo number_format($product['price']);?>
                        </span>
                    </p>
                    <p><a value="<?php echo $key?>" class="rmv_product"><?php echo $this->translate('DELETE');?></a></p>
                </div>
            </td>
            <td>
                <p style="text-align: right;">
                    <input type="text" id="<?php echo $key;?>" class="quantity" name="quantity" value="<?php echo $product['quantity']; ?>" />
                </p>
            </td>
            <td>            
                <p class="payment">
                    <span></span>
                </p>
            </td>
        </tr>
        <?php 
                endforeach;
            endif;
        ?>
        <tr id="empty_cart_row">
            <td colspan="4" class="empty_cart">
                <?php echo $this->translate('MSG_EMPTY_CART');?>
            </td>
        </tr>
        <tr class="end_row">
            <td colspan="2" class="td_total">
                <span><?php echo $this->translate('TOTAL');?></span>
            </td>
            <td class="total_payment">
                <span></span>
            </td>
        </tr>
    </tbody>
    </table>

    <script type="text/javascript">
        var id_store    = '<?php echo $this->store->id?>';
        var cookie_path = '<?php echo $this->pageUrl(array('id_page' => $this->id_page), true);?>';
        var currency    = '<?php echo $this->store->getCurrency();?>';
        var format_currency     = <?php echo $this->format_currency?>;
        var msg_update_shopping_cart_successful    = '<?php echo $this->translate('MSG_UPDATE_SHOPPING_CART');?>';
        var msg_confirm_remove_cart_product         = '<?php echo $this->translate('MSG_CONFIRM_REMOVE_CART_PRODUCT');?>';
        var msg_remove_cart_product_successful = '<?php echo $this->translate('MSG_REMOVE_CART_PRODUCT');?>';
        
        $(document).ready(function(){
            loadShoppingCart();

            $(".quantity").change(function(){
                loadShoppingCart();
                updateShoppingCart();
            });

            $('.cart_product_row').click(function(e){
                var obj = $(this);
                var target = e.target;
                if($(target).attr('class') == 'rmv_product'){
                    id = obj.find('.quantity').attr('id');
                    removeProduct(id, obj);
                }
            });
            
            $('form').submit(function(){
                $('input[type=submit]', this).attr('disabled', 'disabled');
            });
        });
    </script>

    <div class="order_info">
        <div class="order_info_header">
            <h2><?php echo $this->translate('FORM_ORDER_INFO_TITLE');?></h2>
        </div>    
        <?php 
            $this->form_order->setAction($this->pageUrl(array('target' => 'cart'), true));
            echo $this->form_order;
        ?>
    </div>
</div>
<div class="right_col">
    <?php echo $this->partial("index/_purchaseInstruction.phtml", array(
        'store' => $this->store
    ));?>
    
    <?php echo $this->partial("index/_recentViewedProducts.phtml", array(
        'social' => $this->social,
        'rv_products' => $this->rv_products,
        'store' => $this->store
    ));?>
</div>

<?php echo $this->partial('index/scrollTop.phtml');?>